package com.issac.vhr.controller.system.sal;

import com.issac.vhr.entity.RespBean;
import com.issac.vhr.entity.RespPageBean;
import com.issac.vhr.service.EmployeeService;
import com.issac.vhr.service.SalarySobConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/salary/sobcfg/")
public class SalarySobConfigController {

    @Autowired
    SalarySobConfigService salarySobConfigService;
    @Autowired
    EmployeeService employeeService;
    @GetMapping("/")
    public RespPageBean getEmployeeByPageWithSalary(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer size){
        return employeeService.getEmployeeByPageWithSalary(page,size);
    }
    @PutMapping("/")
    public RespBean updateEmployeeSalaryById(Integer eid,Integer sid){
        /*
        * replace into empsalary (eid, sid) VALUES (10,10)
        * 如果eid不存在 则直接添加eid sid, eid存在 则修改eid对应的sid
        * 结果是添加则执行次数为1
        * 结果是修改 则先删除后插入 执行次数为2
        * */
        Integer result = employeeService.updateEmployeeSalaryById(eid, sid);
        if (result ==1 || result==2){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
